//
//  AppDelegate.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/3.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "AppDelegate.h"
#import <XHLaunchAd.h>

@interface AppDelegate ()<UIApplicationDelegate,XHLaunchAdDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [self.window makeKeyAndVisible];
    self.window.backgroundColor = [UIColor clearColor];
    
    //开屏广告
//    [self setLaunchAd];.
    
    MyTabBarViewController *myTabVC = [[MyTabBarViewController alloc] init];
    
    [UIApplication sharedApplication].keyWindow.rootViewController = nil; //
    
    [UIApplication sharedApplication].keyWindow.rootViewController = myTabVC;
    
    return YES;
}

-(void)setLaunchAd{
    
    [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
    
    [XHLaunchAd setWaitDataDuration:5];
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    //配置广告数据
    XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration new];
    //广告停留时间
    imageAdconfiguration.duration = 3;
    //广告frame
    imageAdconfiguration.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
    imageAdconfiguration.imageNameOrURLString = @"开屏广告.png";
    //设置GIF动图是否只循环播放一次(仅对动图设置有效)
    imageAdconfiguration.GIFImageCycleOnce = NO;
    //缓存机制(仅对网络图片有效)
    //为告展示效果更好,可设置为XHLaunchAdImageCacheInBackground,先缓存,下次显示
    imageAdconfiguration.imageOption = XHLaunchAdImageDefault;
    //图片填充模式
    imageAdconfiguration.contentMode = UIViewContentModeScaleToFill;
    //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
//    imageAdconfiguration.openModel = dict;
    //广告显示完成动画
    imageAdconfiguration.showFinishAnimate =ShowFinishAnimateLite;
    //广告显示完成动画时间
    imageAdconfiguration.showFinishAnimateTime = 0.8;
    //跳过按钮类型
    imageAdconfiguration.skipButtonType = SkipTypeTimeText;
    //后台返回时,是否显示广告
    imageAdconfiguration.showEnterForeground = NO;
    
    //设置要添加的自定义视图(可选)
    //imageAdconfiguration.subViews = ...
    
    //显示开屏广告
    [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
    
//    [HTTPTool GET:Get_Home_GetWelcomeList parameters:params
//
//          success:^(id responseObject){
//
//              if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
//
//                  NSDictionary *dict = [[responseObject objectForKey:@"Rows"] firstObject];
//
//
//              }
//
//          }
//
//          failure:^(NSError *error){
//
//          }];
}


/**
 广告点击事件代理方法
 */
-(void)xhLaunchAd:(XHLaunchAd *)launchAd clickAndOpenModel:(id)openModel clickPoint:(CGPoint)clickPoint{
    
    NSLog(@"广告点击事件");
    
    /** openModel即配置广告数据设置的点击广告时打开页面参数(configuration.openModel) */
    
    if(openModel==nil) return;
    
    NSString *dataType = [openModel objectForKey:@"DataType"];
    
//    if ([dataType isEqualToString:@"feed"]) {
//
//        NSString *feedId = [openModel objectForKey:@"DataID"];
//
//        UIViewController *currentVC = [self getCurrentVCFrom:[UIApplication sharedApplication].keyWindow.rootViewController];
//
//        PLPlayInfoViewController *playInfoVC = [[PLPlayInfoViewController alloc] init];
//
//        playInfoVC.feedId = feedId;
//
//        [currentVC.navigationController pushViewController:playInfoVC animated:YES];
//
//    }
    
    NSLog(@"openModel; = %@",openModel);
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
